

import componentMapping from "./mapping"
import * as Icon from '@ant-design/icons';

const IconFont=(props)=>
{
     const S=Icon[props.type]
    return <S/>
}


const defaultMeauList= [];

/**
 * 后端菜单转换为前端菜单
 * @param {*} serverMeau 
 * @returns 
 */
 function translate(serverMeau){
    let r= {
        path:serverMeau.pageUrl,
        title:serverMeau.name,
    }
    if(serverMeau.childen && serverMeau.childen.length>0){
      r.routers=serverMeau.childen.map(u=>translate(u))
    }
    if(serverMeau.parentId !==-1 && serverMeau.icon && serverMeau.icon !=="null"){
      r.icon=<IconFont type={serverMeau.icon}/>;
    }
    r.component=componentMapping(r.path)
    return r;
}


/**
 * 服务器的菜单树
 */
const serverMeauList=async function(){
    let r=await window.MIO.serverMeauList();
    r=r.data;
    let resultMeauList=[]
    r.forEach(u=>{
      let u_r=translate(u);
      resultMeauList.push(u_r);
    })
    return resultMeauList;

};
  
export  {defaultMeauList,serverMeauList} ;